package com.yt.order.provider.service.impl;

import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.core.service.GenericServiceImpl;
import com.yt.order.api.interfaces.ReservationService;
import com.yt.order.api.model.OrderInfo;
import com.yt.order.api.model.Reservation;
import com.yt.order.api.utils.OrderConstants;
import com.yt.order.provider.dao.ReservationDao;

import java.util.List;

/**
 * Created by liujunshi on 15-12-30.
 */
public class ReservationServiceImpl extends GenericServiceImpl<Reservation, Long> implements ReservationService {
	private ReservationDao dao;

	public ReservationServiceImpl() {
	}

	public ReservationServiceImpl(ReservationDao dao) {
		super(dao);
		this.dao = dao;
	}

	@Override
	public List<Reservation> findByOrderId(String orderNo) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_orderNo_L_EQ", orderNo);
		return dao.find(filter);
	}

	@Override
	public Reservation findValidByOrderId(String orderNo) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_orderNo_L_EQ", orderNo);
		filter.addFilter("Q_status_S_NEQ", "3");
		List<Reservation> list = dao.find(filter);
		if(list.isEmpty()){
			return null;
		}
		return list.get(0);
	}
	@Override
	public void updateStatus(String ids, String status) {
		dao.updateStatus(ids, status);
	}

	@Override
	public void updateConfirmed(String ids, String confirmed) {
		dao.updateConfirmed(ids, confirmed);
	}

	@Override
	public void addReservationByOrder(OrderInfo order) {
		Reservation reserve = new Reservation();
		reserve.setGroupName(order.getGroupName());
		reserve.setIdGroupOrder(order.getGroupOrderId());
//		reserve.setAddContent(order.getAddContent());
//		reserve.setAddPrice(order.getAddBasePrice());
		reserve.setAddress(order.getAddress());
		reserve.setAge(order.getAge());
		reserve.setBasePrice(order.getBasePrice());
		reserve.setBuyUser(order.getBuyUser());
		reserve.setComments(order.getBespeaked());
		reserve.setEmail(order.getEmail());
		reserve.setGetReport(order.getReportType());
		reserve.setIdCard(order.getIdCard());
		reserve.setIdInstitution(order.getIdInstitution());
		reserve.setIdOrder(order.getId());
		reserve.setIdProduct(order.getIdProduct());
		reserve.setInstitutionName(order.getInstitutionName());
		reserve.setMobile(order.getMobile());
		reserve.setOrderNo(order.getOrderNo());
		reserve.setProductName(order.getProductName());
		reserve.setPhone(order.getPhone());
		reserve.setReserveDate(null);
		reserve.setSalePrice(order.getSalePrice());
		reserve.setSex(order.getSex());
		reserve.setStatus(OrderConstants.ReservationStatus.New.value);
		reserve.setConfirmed(OrderConstants.ReservationConfirmed.Not.value);
//		reserve.setTijian(order.getTijian());
		reserve.setModifyDate(System.currentTimeMillis());
		dao.insert(reserve);
	}
}
